var initsize=$(".m_c_tab:visible").length;
function addMore(offset,size){
	$.ajax({
        url: 'AddMore',
        data: JSON.stringify({offset: offset,size: size}),
        type: 'post',
        contentType:"application/json;charset=utf-8",
        success: function (data) {
        	if(data.length>0){
        		var table="";
        		$.each(data,function(i,v){
        			if(v.pihao==null)v.pihao='库存不足';
        			table += 
        				"<table class='m_c_tab'>"
        				+"<tbody>"
        				+"<tr>"
        				+"<td rowspan='2' align='left' valign='top' width='10%'>"
        				+"<span class='m_qx p_ck_one p_ck_one130083' tid="+v.spid+"></span>"
        				+"<input id='minnum' value='"+v.zhongbz+"' hidden />"
        				+"<input id='priceZhj' value='"+v.price+"' hidden />"
                        +"<input id='priceChl' value='"+v.priceChl+"' hidden />"
                        +"<input id='jlgg' value='"+v.jlgg+"' hidden />"
                        +"<input id='stock' value='"+v.productBal[0].kxshl+"' hidden />"
        				+"</td>"
        				+"<td rowspan='2' class='pic'>"
        				+ "<a class='m_p_plink touri' href='javascript:void(0)'>"
        				+"<img src='http://www.hnhcyy.com/resource/img/"+v.spid+"/10.jpg' height='88px' width='90px'/>"
        				+"</a>"
        				+"</td>"
        				+"<td class='relative'>"
        				if(v.zengsong!=null){
        					table+="<span class='gift'>礼</span>"
        				}
        				table+="<a href='Shop/Detail?productid="+v.spid+"&sjid="+sjid+"' class='m_p_name escp'>"+v.spmch+"</a>" 
        				+"<span id='zjg' class='f60 p_dg_jg'>￥<span class='price'>";
        				if(v.priceChl!=0&&v.priceChl!=null){
                   			table+=v.priceChl;
                   		}else{
                   			table+=v.price
                   		}
        			table+="</span></span>"
        				+"<span class='m_p_cmbz'>" 
        				+"<span class='m_p_cm2'>批号：≥<em class='pihao' style='font-style:initial;'>"+v.pihao+"</em></span>"  
        				+"<span class='lingshoujia' >￥"+v.lingshoujia+"</span>"
        				+"</span>" 
        				+"<span class='guige' >规格："+v.shpgg+"</span>"
        				+"</td>"
        				+"</tr>"
        				+"<tr>"
        				+"<td align='left' valign='middle'>"
        				+"<span class='m_p_pts'>"
        				+"<div style='color:#999999' class='m_pp bbox icon-reduce'></div>"
        				+"<input class='m_dl_sl bbox' maxlength='4' value="+v.zhongbz+" type='text'>"
        				+"<div class='m_ps bbox icon-add'></div>"
        				+"<input class='m_dl_addcar m_dl_addcar2' value='加入购物车' type='button'>"
        				+"</span></td>"
        				+"</tr>"
        				+"</tbody>"
        				+"</table>"; 
        		});
        		$(".m_prd_d").append(table);
        		isLoaded=true;
        		initsize=$(".m_c_tab:visible").length;
        		//去除全选
        		$(".m_all_b span.car_ck_all").removeClass("c_checked");
        		//价格小数点后如果是1位就转换成2位
        		$(".price,.lingshoujia").each(function(){
        			setScale($(this));
                })
        	}else{
        		$("#loading").hide();
        	}
        }
    });
}
var isLoaded=true;
$(window).scroll(function(){ 
	if (isLoaded == true) {  //前一次加载成功，再执行下一次加载，避免重复调用加载
        if (($("body").height() - $("body").scrollTop()) <= document.documentElement.clientHeight) { 
        	if($("#loading").is(":hidden"))return;
            $("#loading").show(); 
            isLoaded=false;
            var offset=$(".m_c_tab:visible").length;
            console.log(offset);
            var size=6;
            setTimeout(function(){
            	addMore(offset,size);
            },500);
        }
	}
});